package com.xbongbong.saas.model;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.saas.domain.entity.ContractPerformanceEntity;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;

/**
 * @author long.rao
 * @version v1.0
 * @date 2019/2/25 15:56
 * @since v1.0
 */

public interface ContractPerformanceModel extends IModel<ContractPerformanceEntity> {
    /**
     * 数据插入
     * @param entity
     * @throws XbbException 异常
     * @return Integer
     * @author long.rao
     * @date 2019-02-01 15:16
     */
    @Override
    Integer insert(ContractPerformanceEntity entity) throws XbbException;
    /**
     * 数据更新
     * @param entity
     * @throws XbbException 异常
     * @return Integer
     * @author long.rao
     * @date 2019-02-01 15:17
     */
    @Override
    Integer update(ContractPerformanceEntity entity) throws XbbException;
    /**
     * 查询多个
     * @param param 参数
     * @return List<ContractProductEntity>
     * @author long.rao
     * @date 2019-02-01 15:18
     */
    @Override
    List<ContractPerformanceEntity> findEntitys(Map<String, Object> param);
    /**
     * 多条查询
     * @param param 参数
     * @return java.lang.Integer
     * @author long.rao
     * @date 2019-02-01 15:18
     */
    @Override
    Integer getEntitysCount(Map<String, Object> param);
    /**
     * 单条查询
     * @param key 主键ID
     * @param corpid 公司ID
     * @return java.lang.Integer
     * @author long.rao
     * @date 2019-02-01 15:19
     */
    ContractPerformanceEntity getByKey(Long key, String corpid);

    /**
     * 保存实体
     *
     * @param contractPerformanceEntity 实体
     * @return java.lang.Integer
     * @throws XbbException 数据库异常
     * @author feng.zheng
     * @date 2019/2/14 16:42
     */
    Integer save(ContractPerformanceEntity contractPerformanceEntity) throws XbbException;

    /**
     * 根据id删除
     *
     * @param contractPerformanceId 合同业绩id
     * @param corpid 公司id
     * @throws
     * @author long.rao
     * @date 2019-02-25 16:41
     */

    Integer deleteByKey(Long contractPerformanceId, String corpid) throws XbbException;

    /**
     * 根据id删除
     *
     * @param performanceIds 合同业绩id
     * @param corpid 公司id
     * @throws
     * @author long.rao
     * @date 2019-02-25 16:41
     */

    Integer deleteBatch(List<Long> performanceIds, String corpi, Long dataId) throws XbbException;

    /**
     * 设置合同业绩分配del为2
     *
     * @param contractId 合同id
     * @param corpid 公司id
     * @param updateDelList 更新的数据列表
     * @throws
     * @author long.rao
     * @date 2019-02-25 16:41
     */

    Integer setDelByContractId(Long contractId, String corpid, Integer del, List<ContractPerformanceEntity> updateDelList) throws XbbException;


    Integer setApprovalByContractId(Long contractId, String corpid, Integer del, List<ContractPerformanceEntity> updateDelList) throws XbbException;

    /**
     * 批量删除合同业绩分配
     * @author 吴峰
     * @date 2019/3/13 17:16
     * @param contractIdIn 合同id
     * @param corpid 公司id
     * @return java.lang.Integer
     * @throws XbbException 业务异常
     */
    Integer deleteByContractIdIn(List<Long> contractIdIn, String corpid) throws XbbException;

    void insertBatch(List<ContractPerformanceEntity> insertBatchList, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    /**
     * 回滚业绩分配
     * @param performanceEntityList
     * @throws XbbException
     */
    void reductionEsInUpdate(List<ContractPerformanceEntity> performanceEntityList) throws XbbException;

    /**
     * 是否开启了业绩分配
     * @param corpid
     * @return
     * @throws XbbException
     */
    Boolean openDistribution(String corpid) throws XbbException;

    /**
     * 获取脏数据的合同ids
     *
     * @param corpid
     * @return
     * @throws XbbException
     */
    List<Long> getDirtyDataContractIds(String corpid) throws XbbException;

    Integer updateBatch(List<ContractPerformanceEntity> list, String corpid) throws XbbException;
}
